﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using KerriganInterface.IServiceClient;
using System.ServiceModel.Web;
using System.IO;
using KerriganService.DAC;
using KerriganDataContract.Evaluation;
using KerriganDataContract;
using KerriganDataContract.Session;
using KerriganDataContract.Intructor;
using KerriganInterface;

namespace KerriganService.ServiceClient
{
    public class MobileService : IMobileService, IPolicyRetriever
    {
        #region Cross Domain

        public Stream GetSilverlightPolicy()
        {
            return StringToStream(CommonConstant.clientaccesspolicy);
        }
        public Stream GetFlashPolicy()
        {
            return StringToStream(CommonConstant.crossdomain);
        }

        Stream StringToStream(string result)
        {
            WebOperationContext.Current.OutgoingResponse.ContentType = "application/xml";
            return new MemoryStream(Encoding.UTF8.GetBytes(result));
        }

        #endregion


        public List<CustomerByInstructorByDate_Result> GetAllCustomer(int idCustomer)
        {
            try
            {
                return CustomerDAC.GetAllCustomerByInstructorToday(idCustomer);
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message);
            }
        }

        public bool AddMark(int idSession, int idCustomer, CustomerEvaluationDC evaluation)
        {
            try
            {
                return CustomerEvaluationDAC.AddMark(idSession, idCustomer, evaluation);
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message);
            }
        }

        public List<SessionDC> GetSessionsByCustomerWithoutMarkToday( int idCustomer, int idInstructor)
        {
            try
            {
                return SessionCoursesDAC.GetSessionsByCustomerWhitoutMarkTodayForInstructor( idCustomer, idInstructor);
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message);
            }
        }


        public InstructorDC checkLogin(string login, string password)
        {
            try
            {
                return InstructorDAC.CheckLoginInstructor(login, password);
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message);
            }
        }


        public List<SessionDC> GetSessionsByCustomerWithoutMarkToday(int idSession, int idCustomer, int idInstructor)
        {
            throw new NotImplementedException();
        }
    }
}
